package com.relax.mybatis.plugin.sensitive.config;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Getter;
import lombok.Setter;

import com.relax.mybatis.annotation.SensitiveField;
import com.relax.mybatis.annotation.SensitiveJSONFieldKey;
import com.relax.mybatis.constant.SensitiveConstants;

/**
 * @author relax
 * @date 2022/07/05
 * @desc 脱敏配置
 */
@Getter
@Setter
@ConfigurationProperties(prefix = "mybatis.plugin.sensitive")
public class SensitiveProperties {

    /**
     * 占位符，默认为"*"
     */
    private String symbol = SensitiveConstants.DEFAULT_SYMBOL;

    public String getSymbol(SensitiveField sensitiveField) {
        String symbol = sensitiveField.symbol();
        return (null != this.symbol && SensitiveConstants.DEFAULT_SYMBOL.equals(symbol)) ? this.symbol : symbol;
    }

    public String getSymbol(SensitiveJSONFieldKey sensitiveJSONFieldKey) {
        String symbol = sensitiveJSONFieldKey.symbol();
        return (null != this.symbol && SensitiveConstants.DEFAULT_SYMBOL.equals(symbol)) ? this.symbol : symbol;
    }

}
